package com.ruoyi.common.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.service.IOrgUserService;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/oa/orgUserTree")
public class OrgUserController extends BaseController {

    @Autowired
    private IOrgUserService orgUserService;

    @Autowired
    private TokenService tokenService;

    //输出整个公司或指定组织
    @GetMapping("/AllCorp/{id}")
    public AjaxResult initOrgUserTree(@PathVariable String id) {
        if (id.equals("null"))
            return AjaxResult.success(orgUserService.buildDeptTreeSelect(null, true));
        else
            return AjaxResult.success(orgUserService.buildDeptTreeSelect(Long.parseLong(id), true));
    }


    //输出指定人群
    @PostMapping("/users")
    public AjaxResult initUsers(String[] users) {
        //userss数据格式：orgId=userId，orgId=userId
        return null;
    }

    //输出指定组织字段
    @GetMapping("/appointOrgField/{fieldName}")
    public AjaxResult getAppointOrgFieldUsers(@PathVariable String fieldName) {

        return null;
    }

    //输出当前科室
    @GetMapping("/currentOrgForTeam")
    public AjaxResult getCurrentOrgForTeam(HttpServletRequest request) {
        long deptId = tokenService.getLoginUser(request).getUser().getDept().getDeptId();
        return AjaxResult.success(orgUserService.getOrgForTeam(deptId));
    }

    //输出当前部门
    @GetMapping("/currentOrgForDept")
    public AjaxResult getCurrentOrgForDept(HttpServletRequest request) {
        long deptId = tokenService.getLoginUser(request).getUser().getDept().getDeptId();
        return AjaxResult.success(orgUserService.getOrgForDept(deptId));
    }

    //输出当前室经理
    @GetMapping("/currentOrgTeamManager")
    public AjaxResult getCurrentOrgTeamManager(HttpServletRequest request) {
        long deptId = tokenService.getLoginUser(request).getUser().getDept().getDeptId();
        return AjaxResult.success(orgUserService.getOrgTeamManager(deptId));
    }

    //输出当前部门经理
    @GetMapping("/currentOrgDeptManager")
    public AjaxResult getCurrentOrgDeptManager(HttpServletRequest request) {
        long deptId = tokenService.getLoginUser(request).getUser().getDept().getDeptId();
        return AjaxResult.success(orgUserService.getOrgDeptManager(deptId));
    }

    //输出角色
    @GetMapping("/role/{roleId}")
    public AjaxResult getRoleUsers(@PathVariable String roleId) {

        return null;
    }

    //输出计算角色和部门
    @GetMapping("/roleAndDept")
    public AjaxResult getRoleAndDept() {

        return null;
    }

    //输出计算角色和当前部门
    @GetMapping("/roleAndCrruentDept")
    public AjaxResult getRoleAndCrruentDept() {

        return null;
    }


}
